using System;
using System.Globalization;
using jSLCore.Utility.Extensions;

namespace jSLCore.Client.Presentation.jBinding.BaseConverters
{
    public class jSecondsToTimeSpanString : jChainConverter
    {
        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if(value is double)
            {
                var secs = (double)value;
                return TimeSpan.FromSeconds(secs).ToHHMMSS();
            }
            else
            {
                return value;
            }
        }

        public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if(value is TimeSpan)
            {
                var ts = (TimeSpan)value;
                return ts.TotalSeconds;
            }
            return value;
        }
    }
}